<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class ModNews extends MX_Controller{
    public function __construct(){
        parent::__construct();
    }
    public function index(){
        echo "Hello world!";
    }
    public function allMenu($record_number = 12, $record_start = 0){
        $this->load->model(array("modnews/mmodnews_site_news_menu"));
        $data['menu_list'] = $this->mmodnews_site_news_menu->getPidData(0, $record_number, $record_start);
        if($data['menu_list']){
            $this->load->view("modnews/modnews-allMenu", $data);
        }
    }
    public function newsHot($record_number = 4, $record_start = 0){
        $this->load->model(array("modnews/mmodnews_site_news"));
        $data['news_list'] = $this->mmodnews_site_news->getHotData("DESC", $record_number, $record_start);
        if($data['news_list']){
            $this->load->view("modnews/modnews-newsHot", $data);
        }
    }
    public function newsMenu($menu = 1){
        $this->load->model(array("modnews/mmodnews_site_news","modnews/mmodnews_site_news_menu"));
        $this->load->library(array("pagination"));
        if($menu && is_numeric($menu)){
            $data['menu_check'] = $this->mmodnews_site_news_menu->getDataByID($menu);
            if($data['menu_check']){
                $config['base_url'] = base_url(_setURL($data['menu_check']['Name'])."-mnews-".$data['menu_check']['ID'].".html");
                $config['total_rows'] = $this->mmodnews_site_news->countMenuData($menu);
                $config['per_page'] = 5;
                $config['uri_segment'] = 2;
                $this->pagination->initialize($config);
                
                $data['news_list'] = $this->mmodnews_site_news->getMenuData($menu, "DESC", $config['per_page'], (int)($this->uri->segment(2)));
                $this->load->view("modnews/modnews-newsMenu", $data);
            }
        }
    }
    public function allNews(){
        $this->load->model(array("modnews/mmodnews_site_news"));
        $this->load->library(array("pagination"));
        
        $config['base_url'] = base_url("tin-tuc.html");
        $config['total_rows'] = $this->mmodnews_site_news->countAllData();
        $config['per_page'] = 5;
        $config['uri_segment'] = 2;
        $this->pagination->initialize($config);
        
        $data['news_list'] = $this->mmodnews_site_news->getAllData("DESC", $config['per_page'], (int)($this->uri->segment(2)));
        $this->load->view("modnews/modnews-allNews", $data);
    }
    public function detail($id = 1){
        if($id && is_numeric($id)){
            $this->load->model("modnews/mmodnews_site_news");
            $data['news_check'] = $this->mmodnews_site_news->getDataByID($id);
            if($data['news_check']){
                $this->mmodnews_site_news->addHit($id);
                $data['news_list'] = $this->mmodnews_site_news->getSimilarData($data['news_check']['Menu'], $id, "DESC", 5,0);
                $this->load->view("modnews/modnews-detail", $data);
            }
        }
    }
}